#include "ParserStack.h"

void ParserStack::ProcessString(const std::string & str)
{
	//fist check for always
	StackMap::iterator i = m_StackMap.find(-2);
	CallbackMap::iterator u; // create it once here
	if(i != m_StackMap.end())
	{
		u = (*i).second.find(str);
		if(u != (*i).second.end())
		{
			(*u).second((ParserStack*)ptr_tosend);
			return; // it is always. Then it is not stack value for sure
		}
	}
	int lookup = -1; // -1 is global, -2 is check always
	if(!m_Stack.empty())
	{
		lookup = m_Stack.back();
	}
	i = m_StackMap.find(lookup);
	if(i == m_StackMap.end())
	{
		return;
	}
	u = (*i).second.find(str);
	if(u == (*i).second.end())
	{
		return;
	}
	(*u).second((ParserStack*)ptr_tosend);

}